package com.yami.shop.consign.api.controller;

import com.yami.shop.bean.dto.ConsignParam;
import com.yami.shop.bean.vo.ConsignSituationVO;
import com.yami.shop.common.bean.PageDTO;
import com.yami.shop.common.bean.PageVO;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.consign.common.model.ConsignSituation;
import com.yami.shop.consign.common.service.ConsignSituationService;
import com.yami.shop.security.api.model.YamiUser;
import com.yami.shop.security.api.util.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/p/app/consign/situation")
@Tag(name = "app-寄售")
@AllArgsConstructor
public class ConsignController {


    private final ConsignSituationService consignSituationService;


    @PostMapping("/submit")
    @Operation(summary =  "批量寄售", description = "批量寄售")
//    @Decrypt
//    @Encrypt
    public ServerResponseEntity<Void> submitConsign(@RequestBody ConsignParam param) {
        YamiUser user = SecurityUtils.getUser();
        param.setUserId(user.getUserId());
        consignSituationService.submitConsign(param);
        return ServerResponseEntity.success();
    }


    /**
     * 我的寄售分页列表
     * @param pageDTO
     * @param status 0/1:审核中  2/3:已驳回  4:寄售中 5:已出售  6:已下架  7:已取消
     * @return
     */
    @GetMapping("/page")
    @Operation(summary =  "我的寄售", description = "我的寄售")
//    @Encrypt
    public ServerResponseEntity<PageVO<ConsignSituationVO>> page(@Valid PageDTO pageDTO, @RequestParam List<Integer> status) {
        YamiUser user = SecurityUtils.getUser();
        PageVO<ConsignSituationVO> consignPage = consignSituationService.getConsignPage(pageDTO, status, user.getUserId());
        return ServerResponseEntity.success(consignPage);
    }


    @GetMapping("/getById")
    @Operation(summary =  "寄售详情", description = "寄售详情")
//    @Encrypt
    public ServerResponseEntity<ConsignSituationVO> getById(@RequestParam Long id) {
        ConsignSituationVO detail = consignSituationService.getDetail(id);
        return ServerResponseEntity.success(detail);
    }

    @PostMapping("/updateById")
    @Operation(summary =  "修改寄售", description = "修改寄售")
//    @Decrypt
//    @Encrypt
    public ServerResponseEntity<Void> updateById(@RequestBody ConsignSituation situation) {
        YamiUser user = SecurityUtils.getUser();
        situation.setUserId(user.getUserId());
        consignSituationService.updateConsignById(situation);
        return ServerResponseEntity.success();
    }


    @GetMapping("/offById")
    @Operation(summary =  "寄售下架", description = "寄售下架")
//    @Encrypt
    public ServerResponseEntity<Void> offById(@RequestParam Long id) {
        YamiUser user = SecurityUtils.getUser();
        consignSituationService.offById(id, user.getUserId());
        return ServerResponseEntity.success();
    }

    @GetMapping("/cancelById")
    @Operation(summary =  "取消寄售", description = "取消寄售")
//    @Encrypt
    public ServerResponseEntity<Void> cancelById(@RequestParam Long id) {
        YamiUser user = SecurityUtils.getUser();
        consignSituationService.cancelConsignById(id, user.getUserId());
        return ServerResponseEntity.success();
    }

    @GetMapping("/ua/getInfo")
    @Operation(summary =  "获取寄售详情", description = "获取寄售详情")
//    @Encrypt
    public ServerResponseEntity<Map<String, Object>> getinfoById(@RequestParam Integer id){
        Map<String, Object> stringObjectMap = consignSituationService.getinfoById(id);
        return ServerResponseEntity.success(stringObjectMap);
    }







}
